//用循环队列模拟实现
public class MyCircularQueue {
    public int[] arr;
    public MyCircularQueue(int x) {
        arr = new int[x];
    }
    //头
    public int front;

    //尾
    public int tail;

    //入队列
    public boolean enQueue(int val) {
        if(isFull()) {
            //如果满了
            return false;
        }else {
            //没有满
            arr[tail] = val;
            tail = (tail+1) % arr.length;
            return true;
        }
    }

    //出队列
    public boolean deQueue() {
        if(isEmpty()) {
            //如果为空
            return false;
        }else {
            //不为空
            int ret = arr[front];
            front = (front + 1) % arr.length;
            return true;
        }
    }

    //获取队首元素
    public int Front() {
        if(isEmpty()) {
            return -1;
        }
        return arr[front];
    }

    //获取队尾元素
    public int Rear() {
        if(isEmpty()) {
            return -1;
        }
        int index = (tail == 0) ? (arr.length - 1) : (tail - 1);
        return arr[index];
    }
    //判断是否为空
    public boolean isEmpty() {
        return front == tail;
    }

    //判断是否为满 舍弃一个空间来判断,所以就相当于有一个大小为4的数组，现在里面只能存放三个元素
    public boolean isFull() {
        return (tail + 1) % arr.length == front;
    }
}
